package com.newway.back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newway.back.entity.SysUserEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface SysUserMapper extends BaseMapper<SysUserEntity> {

    /**
     * 根据用户id获取角色列表字符串
     * @param id
     * @return
     */
    @Select(" select DISTINCT  sr.code from sys_user su inner join sys_user_role sur on su.id  = sur.user_id inner join sys_role sr on sur.role_id =sr.id where su.id =#{id}  ")
    List<String> getRolesById(@Param("id") Integer id);

    /**
     * 根据角色id获取用户权限列表字符串
     * @param id
     * @return
     */
    @Select(" select distinct sm.perms from sys_user su inner join sys_user_role sur on su.id  = sur.user_id inner join sys_role sr on sur.role_id =sr.id\n" +
            "inner join sys_role_menu srm on srm.role_id =su.id inner join sys_menu sm on sm.id = srm.menu_id\n" +
            "where su.id =#{id} and sm.`type` ='2' ")
    List<String> getPermsById(@Param("id") Integer id);


    @Select("select distinct su.id from sys_user su inner join sys_user_role sur on su.id= sur.user_id inner join sys_role sr on sr.id = sur.role_id where sr.id =#{roleId} ")
    List<Integer> selectUserIdByRoles(@Param("roleId") String roleId);
}
